package de.blitzcoder.cddatabase.gui.cdtable;

import de.blitzcoder.cddatabase.data.CD;
import de.blitzcoder.cddatabase.gui.datatable.DataTableRow;
import javax.swing.JButton;

/**
 *
 * @author blitzcoder
 */
public class CDTableRow implements DataTableRow {

    private CD cd;

    public CDTableRow(CD cd) {
        this.cd = cd;
    }

    @Override
    public Object getColumn(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return cd.getID();
            case 1:
                return cd.getName();
            case 2:
                return cd.getArtist();
            case 3:
                return cd.getYear()+"";
        }
        throw new IllegalArgumentException("Illegal column");
    }

    public CD getCD() {
        return this.cd;
    }

    @Override
    public boolean matches(String str) {
        str = str.toLowerCase();
        return cd.getName().toLowerCase().indexOf(str) != -1 || cd.getArtist().toLowerCase().indexOf(str) != -1 || str.equals(cd.getID()+"") || str.equals(cd.getYear()+"");
    }

}
